﻿using System;
using ProcessManagerXNA.Process;
using Microsoft.Xna.Framework;

namespace ProcessManagerXNA.Processes
{
    public class FadeScreenProcess : BaseProcess
    {
        private readonly Color color;
        private readonly Game1 game;

        public readonly TimeSpan TotalDuration;
        public float Value { get; private set; }

        public FadeScreenProcess(Game1 game, Color color, TimeSpan duration)
        {
            this.color = color;
            this.game = game;

            TotalDuration = duration;
        }

        public override void OnInit()
        {
            base.OnInit();
            Value = 0f;
        }

        public override void OnUpdate(Microsoft.Xna.Framework.GameTime gameTime)
        {
            Value += gameTime.ElapsedGameTime.Milliseconds / ((float)TotalDuration.TotalMilliseconds);

            if (Value >= 1f)
            {
                Value = 1f;
                Succeed();
            }

            game.SetOverlayColor(color * Value);
        }

        public override void OnSuccess()
        {
                
        }

        public override void OnFail()
        {
        
        }

        public override void OnAbort()
        {

        }
    }
}
